<?php
/**
 * Created by PhpStorm.
 * User: Windows
 * Date: 2015/11/16
 * Time: 17:00
 */

class OrderModel extends BaseModel
{
    private $_table;
    protected $_name = 'sale_order';
    protected $_isbug = false;


    public function getOrderTrade($where,$limit){
        $this->_table = new self ();
        $db = $this->_table->getAdapter ();
        if(!$where){
            $where=" 1=1 ";
        }
        $sql = $db->select ()->from ("sale_order_sku as sos" ,array("num"))
            ->joinLeft("sale_order as so","so.id = sos.order_id",array("create_time","status"))
            ->joinLeft("users_invoice as ui","ui.id = so.business_id",array("contacts"))
            ->joinLeft ( "product as p", "sos.product_id = p.id", array("product_name"))
            ->joinLeft ( "product_cates as pc", "p.cate_id = pc.id", "cate_name" )
            ->joinLeft ( "product_brands as pb", "p.brand_id = pb.id", "brand_name" )
            ->where ( $where )->__toString ();
        if ($this->_isbug == true) {
            echo  __METHOD__.": ".$sql . "<hr/>";
        }
        if(!empty($limit)){
            $sql.="limit {$limit}";
        }
        return $db->fetchAll( $sql );
    }

}